<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width,inital-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="format-detection" content="telephone=no, email=no"/>
    <title>骡窝窝积分商城</title>
    <link href="/mall/css/reset2.css" rel="stylesheet" type="text/css"/>
    <link href="/mall/css/css2.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="/mall/css/base.css"/>
    <link rel="stylesheet" type="text/css" href="/mall/css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="/mall/css/loaders.min.css"/>
    <link rel="stylesheet" type="text/css" href="/mall/css/loading.css"/>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/mall/css/base2.css"></script>
    <script src="/mall/js/jquery.lazyload.js"></script>
    <script src="/mall/js/rem.js"></script>
    <script src="/mall/js/aui-car2.js"></script>
    <script src="/js/plugins/form/jquery.form.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script>
        $(function () {
            var user = $.parseJSON(sessionStorage.getItem("user"));
            var params = getParams();
            console.log(params);
            var arr = $.map(params, function (a) {
                return a;
            })
            //console.log(arr);
            jQuery.ajaxSettings.traditional = true;
            if (arr) {
                $.get("/persons", {ids: arr, type: 1}, function (data) {
                    var count = 0;
                    //console.log(data.list[0].number);
                    //console.log(data);
                    var product = data.list.length;
                    if (params.id0) {
                        $("#listProduct").renderValues(data);
                        $(".transFee").renderValues(data);
                        //循环获取所有积分
                        $.each(data.list, function (index, ele) {
                            count += ele.product.integral * ele.number;
                        })
                        $("#unit").html(count);
                        $("#dsp").html(count);

                    } else {
                        $.get("/products/" + params.id, function (data) {
                            var json = {product: data}
                            var json1 = {list: json}
                            console.log(json1);
                            $("#listProduct").renderValues(json1);
                            $(".transFee").renderValues(json1);
                            count = data.integral;
                            $("#unit").html(count);
                            $("#dsp").html(count);
                        })

                    }

                    //获取总积分
                    console.log(arr);
                    $.get("/integrals/" + user.id, function (data1) {
                        $("#immediatePayment").click(function () {
                            if (data1 >= $("#unit").html()) {
                                // jQuery.ajaxSettings.traditional = true;
                                $.ajax({
                                    type: "PUT",
                                    data: {arr: arr},
                                    url: "/persons/updateType"
                                })
                                var count = data1 - $("#unit").html();
                                var dataParams = {};
                                dataParams["userId"] = user.id;
                                dataParams["totalIntegral"] = count;
                                console.log(dataParams);
                                $.ajax({
                                    type: "PUT",
                                    data: dataParams,
                                    url: "/integrals/updateIntegral"
                                })
                                location.href = "/mine/order-ok.html?id=" + $("#unit").html();
                            } else {
                                $(document).dialog({
                                    overlayClose: true,
                                    content: '积分不足!'
                                });
                            }
                        })
                    })
                })
            }
        })
    </script>
</head>

<body>
<div class="wrap clearfix">
    <header class="mui-bar mui-bar-nav" id="header">
        <a class="" href="javascript:history.go(-1)">
            <i class="iconfont icon-fanhui"></i>
        </a>
        <h4>订单结算</h4>
    </header>
    <div class="clear"></div>
    <!-- header end -->
    <ul class="list-tab btline mt10 clearfix">
        <li class="item">
            <a class="order-addr tap pl-24 arrow" href="/mine/myAddress.html">
                <i class="icon-addr icon"></i>
                <span class="">银河系地球村上海e通大世界A座402</span><span class="fr c2">新的地址</span>
                <i class="icon-arrow icon"></i>
            </a>
        </li>
    </ul>
    <ul class="plist2 clearfix" id="listProduct">
        <li class="clearfix" render-loop="list">
            <a data-href="/mall/productDetail.html?id=" class="tap clearfix">
                <div class="imgbox box-sizing"><img render-src="list.product.imgUrls" class="lazy"/></div>
                <div class="text-box box-sizing">
                    <div class="name" render-html="list.product.info"></div>
                    <div class="price-box">
                        <span class="red unit" render-html="list.product.integral"></span>积分
                        <span class="num">x<i render-html="list.number">1</i></span>
                    </div>
                </div>
            </a>
        </li>

    </ul>

    <div class="title-bt">结算</div>
    <ul class="list-tab btline mt10 clearfix">
        <li class="item">
            <div class="tap">
                <span class="name">运费</span>
                <span class="dsp c5">免邮</span>
            </div>
        </li>
        <li class="item">
            <div class="tap">
                <span class="name">订单总额</span>
                <div class="transFee">
                    <span class="dsp">积分</span>
                    <span class="dsp" id="dsp"></span>
                </div>
            </div>
        </li>
    </ul>

    <div class="title-bt">支付方式</div>
    <ul class="list-tab mt10 mb10 btline clearfix" id="payment">
        <li class="item">
            <div class="tap pl-24 check">
                <div class="icon-24"><img src="/mall/mall/car2/images/zfb.png"></div>
                <span class="name">支付宝支付</span>
                <label class="ico-check active"><input type="radio"></label>
            </div>
        </li>
        <li class="item">
            <div class="tap pl-24 check">
                <div class="icon-24"><img src="/mall/mall/car2/images/weixin.png"></div>
                <span class="name">微信支付</span>
                <label class="ico-check"><input type="radio"></label>
            </div>
        </li>
        <li class="item">
            <div class="tap pl-24 check">
                <div class="icon-24"><img src="/mall/mall/car2/images/yinlian.png"></div>
                <span class="name">网银支付</span>
                <label class="ico-check"><input type="radio"></label>
            </div>
        </li>
    </ul>

    <!-- footer begin -->
    <div class="clear"></div>
    <nav class="bot-nav">
        <div class="count-box totalMoney">共计 1 件，总额：
            <!--渲染金额-->
            <span class="red unit"> <font class="unit" id="unit"></font>积分</span>
        </div>
        <a href="javascript:" class="ljgm-btn pa paying" id="immediatePayment">立即支付</a>
    </nav>
</div>
<script>
    //图片懒加载
    $("img.lazy").lazyload({
        effect: "fadeIn",
        threshold: 1000,
    });

    $(function () {
        $("#payment .tap").bind({
            tap: function () {
                $("#payment .ico-check").removeClass("active");
                $(this).find(".ico-check").addClass("active");
            }
        });
    });
</script>
</body>
</html>